﻿Public Class Registrar_compra
    Inherits System.Web.UI.Page

    Protected Sub TB_codProduc_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles TB_codProduc.TextChanged
        Dim cod_producto As String
        Dim nombre_producto As String
        Dim precio_producto As String
        Dim storexpress As New DCStorexpressDataContext
        Try
            Dim query = storexpress.p_buscar_producto(TB_codProduc.Text)
            Dim registro = query.First

            cod_producto = registro.COD_PRODUCTO
            nombre_producto = registro.NOMBRE_PRODUCTO
            precio_producto = registro.PRECIO_PRODUCTO

            TB_codProduc.Text = cod_producto
            TB_nombprod.Text = nombre_producto
            TB_valoruni.Text = precio_producto

        Catch ex As InvalidOperationException
            If MsgBox("no hay registros coincidentes") Then

            End If


        End Try
    End Sub

   

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub BT_atras_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BT_atras.Click
        Response.Redirect("~/Registrar.aspx")
    End Sub

    Protected Sub BT_registro_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BT_registro.Click
        Dim datacontex As New DCStorexpressDataContext
        Dim mensaje As MsgBoxResult
        mensaje = MsgBox("¿Desea Guardar Registro?", MsgBoxStyle.OkCancel, "REGISTRO")
        If mensaje = MsgBoxResult.Ok Then
            MsgBox("Registro Guardado")

            datacontex.INSERTAR_COMPRA(Me.TB_compra.Text, Me.TB_factura.Text, Me.TB_fecha.Text, Me.TB_numdocempl.Text, Me.TB_nombreemple.Text, Me.TB_numdoccliente.Text, Me.TB_cliente.Text, TB_codProduc.Text, Me.TB_nombprod.Text, Me.TB_valoruni.Text, Me.TB_cantidad.Text, Me.TB_valortotal.Text)

            TB_compra.Text = ""
            TB_codProduc.Text = ""
            TB_nombprod.Text = ""
            TB_valoruni.Text = ""
            TB_cantidad.Text = ""
            TB_valortotal.Text = ""


        End If

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BT_compra.Click
        TB_compra.Text = ""
        TB_factura.Text = ""

        TB_numdocempl.Text = ""
        TB_nombreemple.Text = ""
        TB_numdoccliente.Text = ""
        TB_cliente.Text = ""
        TB_codProduc.Text = ""
        TB_nombprod.Text = ""
        TB_valoruni.Text = ""
        TB_cantidad.Text = ""
        TB_valortotal.Text = ""
    End Sub

   

End Class


